home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
- From: Dan Pop <danpop@mail.cern.ch>
- Newsgroups: comp.lang.c
- Subject: Re: quick decision: is n a power of 2?
- Date: Thu, 25 Jan 1996 13:45:27 +0100
- Organization: CERN European Lab for Particle Physics
- Message-ID: <9601251245.AA12220@dxmint.cern.ch>
- References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca> <TANMOY.96Jan21104404@qcd.lanl.gov> <4e6rs0$dvl@ns.RezoNet.NET>
- X-NNTP-Posting-Host: hpl3sn03.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
-
- ray@ultimate-tech.com (Ray Dunn) writes:
-
- >In referenced article, Tanmoy Bhattacharya says...
- >>Consider x = 0...0101. -x = 1...1011
- >>-x & x == 1. So I cannot quite figure out what was meant above.
- >>
- >>x && !(x & ~-x) is a possible solution: But since ~-x is the same as
- >>(x-1), this is the same as an already posted answer. (I am sorry that
- >>in my hurry I missed the x && bit in a previous post).
- >>
- >>Instead of calling for 2's complement arithmetic, I prefer to say that
- >>these should only be used for unsigned types.
- >
- >I don't undersand this last comment. None of the examples you show
- >work except in two's complement arithmetic.
-
- The unary minus operator applied to an unsigned integer is always evaluated
- using two's complement arithmetic, no matter what representation is used
- by the implementation for signed integers.
-
- Tanmoy's point was that by restricting the solution to unsigned integers,
- the representation of signed integers becomes irrelevant.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-